<script setup>
import { ref } from 'vue'
import { artGetChannelsService } from '@/api/article'
const channelList = ref([])

defineProps({
  modelValue: {
    type: [Number, String]
  }
  //   width: {
  //     type: String
  //   }
})

const emit = defineEmits(['update:modelValue'])

const getChannelList = async () => {
  const res = await artGetChannelsService()
  channelList.value = res.data.data
}
getChannelList()
</script>
<template>
  <!-- 
        :modelValue="modelValue" => 父传子，渲染父组件传过来的cate_id
        @update:modelValue="emit('update:modelValue', $event)" => 子传父，触发emit事件，更新父组件中cate_id的值
     -->
  <!-- :style="{ width }" -->
  <el-select
    style="width: 200px"
    :modelValue="modelValue"
    @update:modelValue="emit('update:modelValue', $event)"
  >
    <!-- label 展示给用户看的  value 提交给后台的 -->
    <el-option
      v-for="channel in channelList"
      :key="channel.id"
      :label="channel.cate_name"
      :value="channel.id"
    ></el-option>
  </el-select>
</template>
